import React, {Component} from 'react';
import {
	AppRegistry,
	Dimensions,
	Platform,
	NativeModules,
	DeviceInfo,
	StyleSheet,
	Image,
	Text,
	View,
	TextInput,
	PixelRatio,
	TouchableOpacity,
	ScrollView,
	AsyncStorage
} from 'react-native';

var Common = require('./common');
// iPhoneX
const X_WIDTH = 375;
const X_HEIGHT = 812;

// screen
const SCREEN_WIDTH = Dimensions.get('window').width;
const SCREEN_HEIGHT = Dimensions.get('window').height;

const pixelRatio = PixelRatio.get();
const dismissKeyboard = require('dismissKeyboard');
export default class SystemSetting extends Component {
	// 此处设置 Tab 的名称和一些样式，这里的会覆盖掉配置路由文件的样式，下面会讲
	static navigationOptions = {
		headerTitle: '设置',
		tabBarLabel: '设置',

	};

	constructor(props) {
		super(props);
		this.state = {
			iphonex: false,
			showCeng: false,
			str: '推荐',
			news: [{"title": "ssss"}, {"title": "ssss"},],
			imgsrc: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514356844477&di=7c57fde0860194258cbec5c2720e0cf5&imgtype=0&src=http%3A%2F%2Fwww.swkweike.com%2Fdata%2Fuploads%2F2015%2F05%2F26%2F20430804665564348adc669.png',
		};
	}

	isIphoneX() {

		return (

			Platform.OS === 'ios' &&

			((SCREEN_HEIGHT === X_HEIGHT && SCREEN_WIDTH === X_WIDTH) ||

				(SCREEN_HEIGHT === X_WIDTH && SCREEN_WIDTH === X_HEIGHT))

		)

	}


	ifIphoneX() {
		var flag = this.isIphoneX();
		if (flag) {
			console.log('true')
			this.setState({
				iphonex: true
			})
		} else {
			console.log('false')
			this.setState({
				iphonex: false
			})
		}
	}


	login() {
		var _this = this;
		Common.ajaxPost(Common.url + 'login.php', function (res) {
			if (res.code == "0000") {

			}
		}.bind(this), {verify: '08login', t: ''});
	}

	toRegister() {
		this.props.navigation.navigate('Register')
	}

	toChangePassword() {
		this.props.navigation.navigate('ChangePassword')
	}

	toQuestion() {
		this.props.navigation.navigate('QuestionList')
	}

	toAboutUs() {
		this.props.navigation.navigate('AboutUs')
	}

	tuichu(){
		AsyncStorage.removeItem('cookie');
		AsyncStorage.removeItem('logindata');
		this.props.navigation.navigate('AuthLoadingScreen');
	}


	componentWillMount() {
		this.ifIphoneX();
		// console.log(this.props.navigation.state.params)
		// if(this.props.navigation.state.params.from){
		//   this.setState({
		//     from:this.props.navigation.state.params,
		//   })
		// }
	}

	render() {
		const {navigate} = this.props.navigation;
		return (
			<View style={styles.container}>

				<View>
					<TouchableOpacity style={styles.nav2} onPress={this.toChangePassword.bind(this)}>
						<Text style={{flex: 1, marginLeft: 12, fontSize: 16,}}>修改密码</Text>
						<Image style={{width: 22, height: 22}} source={require('./images/jiantou.png')}/>
					</TouchableOpacity>
					<TouchableOpacity style={[styles.nav2, {borderBottomWidth: 0}]} onPress={this.toQuestion.bind(this)}>
						<Text style={{flex: 1, marginLeft: 12, fontSize: 16,}}>常见问题</Text>
						<Image style={{width: 22, height: 22}} source={require('./images/jiantou.png')}/>
					</TouchableOpacity>
				</View>
				<View style={{height: 8, backgroundColor: '#f5f5f5'}}></View>
				<View>
					{/*<TouchableOpacity style={styles.nav2}>*/}
						{/*<Text style={{flex: 1, marginLeft: 12, fontSize: 16,}}>消息设置</Text>*/}
						{/*<Image style={{width: 22, height: 22}} source={require('./images/jiantou.png')}/>*/}
					{/*</TouchableOpacity>*/}
					<TouchableOpacity style={[styles.nav2, {border: 0}]}>
						<Text style={{flex: 1, marginLeft: 12, fontSize: 16,}}>清除数据</Text>
					</TouchableOpacity>
					<TouchableOpacity style={[styles.nav2, {borderBottomWidth: 0}]} onPress={this.toAboutUs.bind(this)}>
						<Text style={{flex: 1, marginLeft: 12, fontSize: 16,}}>关于我们</Text>
						<Image style={{width: 22, height: 22}} source={require('./images/jiantou.png')}/>
					</TouchableOpacity>
				</View>
				<View style={{height: 8, backgroundColor: '#f5f5f5'}}></View>
				<View>
					<TouchableOpacity style={styles.tuichu} onPress={this.tuichu.bind(this)}>
						<Text style={{color: 'rgb(78,129,243)', fontSize: 18}}>退出登录</Text>
					</TouchableOpacity>
				</View>
			</View>
		);
	}
}

const styles = StyleSheet.create({
	container: {
		flex: 1,
		height: Common.screenHeight,
		backgroundColor: '#f5f5f5',
	},
	mineTop: {
		flexDirection: 'row',
		alignItems: 'center',
		paddingLeft: 16,
		paddingRight: 25,
		paddingTop: 25,
		paddingBottom: 25,
	},
	newsItem: {
		marginLeft: 20,
		marginRight: 20,
		paddingTop: 15,
		paddingBottom: 15,
		borderBottomColor: '#e9e9e9',
		borderBottomWidth: 1,
	},
	user: {
		flexDirection: 'row',
		alignItems: 'center',
	},
	userText: {
		fontSize: 16
	},
	newsTitle: {
		fontSize: 18,
		lineHeight: 22,
		paddingBottom: 10,
		paddingTop: 10,
	},
	imgs: {
		flexDirection: 'row',

		alignItems: 'center',
	},
	imgsItem: {
		width: (Common.screenWidth - 70) / 3,
		height: (Common.screenWidth - 70) / 3,
		marginLeft: 5,
		marginRight: 5
	},
	hudong: {
		flexDirection: 'row',
		alignItems: 'center',
		justifyContent: 'flex-end',
		paddingTop: 10,
	},
	hodongItem: {
		flexDirection: 'row',
		alignItems: 'center',
		justifyContent: 'center',
		marginLeft: 15,
	},
	quicknav: {
		flexDirection: 'row',
		alignItems: 'center',
		justifyContent: 'center',
		paddingBottom: 16,
		paddingTop: 16,
	},
	quicknavItem: {
		flex: 1,
		flexDirection: 'column',
		alignItems: 'center',
		justifyContent: 'center'
	},
	quicknavItemText: {
		fontSize: 16,
		paddingTop: 10,
	},
	nav2: {
		flexDirection: 'row',
		alignItems: 'center',
		justifyContent: 'center',
		paddingLeft: 25,
		paddingRight: 25,
		height: 50,
		borderBottomColor: '#e9e9e9',
		borderBottomWidth: 1,
		backgroundColor: '#fff',
	},
	tuichu: {
		flexDirection: 'row',
		alignItems: 'center',
		justifyContent: 'center',
		backgroundColor: '#fff',
		height: 53,
	}

});
